
#include <omp.h>
#include <iostream>
#include <cmath>
#include <list>
#include <tuple>
#include <chrono>

#include "data_format.hpp"
#include "data_output.hpp"
#include "function.hpp"
#include "integral_calc.hpp"

int main(int argc, char* argv[]){
  freopen("input.txt", "r", stdin);

  size_t test_count = 0;
  Interval_t main_interval;
  double param = 0;
  std::list<trip_t> integral_list;

  std::cin >> main_interval.inf;
  std::cin >> main_interval.sup;
  std::cin >> param;
  std::cin >> test_count;

  for(int i = 0; i < test_count; ++i){

    double integral_val = 0;

    double calc_param = 0;
    std::cin >> calc_param;
    main_interval.increase_count = (calc_param >=1)? calc_param : 1.0 / calc_param;

// CALC START
    auto t_start = std::chrono::high_resolution_clock::now();

    integral_val = integral_calc(param, main_interval);

// Get Error
    double exact_val = primal(main_interval.sup, param) - primal(main_interval.inf, param);
    double err = fabsl(integral_val - exact_val) / fabsl(integral_val);
// Get Time    
    const auto t_end = std::chrono::high_resolution_clock::now();
    double difftime = std::chrono::duration<double>(t_end - t_start).count();

// CALC END

// Make Record
    integral_list.push_back(std::make_tuple(main_interval.increase_count, err, difftime));
  }

  print_table_2(integral_list);

  return 0;
}
